<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员 - 用户管理</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        /* 复用 index.html 的样式 */
        :root {
            --primary-color: #ff6a00;
            --success-color: #52c41a;
            --error-color: #ff4d4f;
            --text-dark: #1f2d3d;
            --text-light: #5e6c84;
            --border-color: #e4e7ed;
            --shadow-default: 0 4px 12px rgba(0,0,0,0.08);
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #f5f7fa;
            line-height: 1.5;
            margin: 0;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            display: flex;
        }

        .sidebar {
            width: 240px;
            background: white;
            box-shadow: var(--shadow-default);
            padding: 20px 0;
        }

        .nav-title {
            color: var(--text-dark);
            font-size: 16px;
            padding: 12px 24px;
            font-weight: 600;
        }

        .nav-item {
            display: block;
            padding: 12px 24px;
            color: var(--text-light);
            text-decoration: none;
            transition: all 0.3s;
        }

        .nav-item:hover, .nav-item.active {
            color: var(--primary-color);
            background: #f5f5f5;
        }

        .main-content {
            flex: 1;
            padding: 32px;
        }

        .ant-card {
            background: white;
            padding: 32px;
            border-radius: 12px;
            box-shadow: var(--shadow-default);
        }

        .ant-title {
            color: var(--text-dark);
            font-size: 20px;
            margin: 0 0 24px;
            font-weight: 600;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }

        th {
            background: #fafafa;
            color: var(--text-dark);
            font-weight: 600;
        }

        td {
            color: var(--text-light);
        }

        .superuser {
            color: var(--success-color);
            font-weight: bold;
        }

        .staff {
            color: var(--primary-color);
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 左侧导航 -->
        <div class="sidebar">
            <div class="nav-title">管理员功能</div>
            <a href="{% url 'admin_user_management' %}" class="nav-item active">👥 用户管理</a>
            <a href="{% url 'survey_list' %}" class="nav-item">📋 所有问卷</a>
            <a href="{% url 'home' %}" class="nav-item">🚪 返回主页</a>
        </div>

        <!-- 右侧内容 -->
        <div class="main-content">
            <div class="ant-card">
                <h2 class="ant-title">用户管理</h2>
                <table>
                    <thead>
                        <tr>
                            <th>用户名</th>
                            <th>邮箱</th>
                            <th>注册时间</th>
                            <th>超级用户</th>
                            <th>工作人员</th>
                            <th>问卷数量</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in users %}
                        <tr>
                            <td>{{ user.username }}</td>
                            <td>{{ user.email|default:"未填写" }}</td>
                            <td>{{ user.date_joined|date:"Y-m-d H:i" }}</td>
                            <td class="{% if user.is_superuser %}superuser{% endif %}">
                                {{ user.is_superuser|yesno:"是,否" }}
                            </td>
                            <td class="{% if user.is_staff %}staff{% endif %}">
                                {{ user.is_staff|yesno:"是,否" }}
                            </td>
                            <td>{{ user.survey_count }}</td>
                            <td>
                                    <form method="post" action="{% url 'delete_user' user.id %}" onsubmit="return confirm('确认删除该用户？');">
                                        {% csrf_token %}
                                        <button type="submit" style="background:#ff4d4f; color:white; border:none; padding:5px 10px; border-radius:4px; cursor:pointer;">
                                            删除
                                        </button>
                                    </form>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="6">暂无用户数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>